package psrc.logic.pages.consultaClientesRedes;

import java.util.ArrayList;
import java.util.List;

import psrc.logic.pages.base.ControllerBase;
import psrc.logic.pages.rede.RedeModel;
import psrc.logic.util.beans.ClienteBean;
import psrc.logic.util.beans.RedeBean;

public class LoadClienteRedeSeeController extends ControllerBase {

	private static final long serialVersionUID = 1L;

	List<ClienteBean> clientes = new ArrayList<ClienteBean>();
	List<RedeBean> redeBeans = new ArrayList<RedeBean>();
	List<String> redes = new ArrayList<String>();

	@Override
	public String executeController() throws Exception {
		try {
			this.redeBeans = new RedeModel().getRedesList();
			for(int i = 0; i < redeBeans.size(); i++){
				redes.add(redeBeans.get(i).getIdRede() + ", " + redeBeans.get(i).getNome());
			}
		} catch (Exception e) {
			return "genericError";
		}
		return SUCCESS;
	}

	public String executeLoadList() throws Exception {
		try{
			int idRede = Integer.parseInt(redes.get(0).split(",")[0]); 
			this.clientes = new ClienteRedeModel().getListByIdRede(idRede);
			
			this.redeBeans = new RedeModel().getRedesList();
			redeBeans.clear();
			for(int i = 0; i < redeBeans.size(); i++){
				redes.add(redeBeans.get(i).getIdRede() + ", " + redeBeans.get(i).getNome());
			}
		}catch (Exception e) {
			return "genericError";
		}
		return SUCCESS;
	}

	public List<RedeBean> getRedeBeans() {
		return redeBeans;
	}

	public void setRedeBeans(List<RedeBean> redeBeans) {
		this.redeBeans = redeBeans;
	}

	public List<String> getRedes() {
		return redes;
	}

	public void setRedes(List<String> redes) {
		this.redes = redes;
	}

	public List<ClienteBean> getClientes() {
		return clientes;
	}

	public void setClientes(List<ClienteBean> clientes) {
		this.clientes = clientes;
	}

}
